package controller.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import paging.ADNoticPaging;
import paging.Paging;
import Bean.noticeBean;
import dao.noticeDao;

public class adminListController implements Controller{

	private noticeDao adntdao;

	public void setAdntdao(noticeDao adntdao) {
		this.adntdao = adntdao;
	}

	Paging pageInfo = null;

	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse arg1) throws Exception {

		String pageNumber = request.getParameter("pageNumber");
		String pageSize = request.getParameter("pageSize");
		String contextPath = request.getContextPath();
		String url = contextPath + " onclick=\"ajaxPagingNT('AdminuserList.admin";

		int totalCount = adntdao.count();

		ADNoticPaging pageInfo = new ADNoticPaging(pageNumber, pageSize, totalCount, url);

		ModelAndView mv = new ModelAndView();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("beginRow",pageInfo.getBeginRow());
		map.put("endRow",pageInfo.getEndRow());	

		List<noticeBean> noticeList = adntdao.getnoticeList(map);
		mv.addObject("noticeList", noticeList);
		mv.addObject("pageInfo",pageInfo);
		mv.setViewName("AdminnoticeList");

		return mv;
	}
}
